package leetcodecompetition.S121;

import org.junit.jupiter.api.Test;

/**
 * @Author: Siantar
 * @Date: 2024-01-06-23:11
 * @Description: 1.0
 */
public class T100159 {
    int MAX = 500000;

    public int minimumOperationsToMakeEqual(int x, int y) {
        int[] dp = new int[MAX];
        return Math.min(dfs1(x, y), dfs2(x, y));
    }

    public int dfs1(int x, int y) {
        System.out.println(x+" - "+y);
        if (x == 0) return Integer.MAX_VALUE / 2;
        int i = x + 2;
        for (; i >= x - 2 && x >= 0; i--) {
            if (i % 5 == 0) break;
        }
        int r = Math.abs(x - i) + 1;
        x = i / 5;
        return Math.min(dfs1(x, y), dfs2(x, y)) + r;
    }

    public int dfs2(int x, int y) {
        System.out.println(x+" -- "+y);
        if (x == 0) return Integer.MAX_VALUE / 2;
        int i = x + 5;
        for (; i >= x - 5 && x >= 0; i--) {
            if (i % 5 == 0) break;
        }
        int r = Math.abs(x - i) + 1;
        x = i / 5;
        return Math.min(dfs1(x, y), dfs2(x, y)) + r;
    }

    @Test
    public void test() {
        System.out.println(minimumOperationsToMakeEqual(26, 1));
    }
}
